package com.tanhua.admin.module.dynamicmanage.controller;

import cn.hutool.core.util.ObjectUtil;
import com.tanhua.admin.module.dynamicmanage.service.MessagePassAndRejectService;
import com.tanhua.admin.module.dynamicmanage.service.impl.MessagePassAndRejectServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Slf4j
@RequestMapping("manage/messages")
public class MessagePassAndRejectController {

    @Autowired
    private MessagePassAndRejectServiceImpl messagePassAndRejectService;

    /**
     * 消息通过
     */
    @PostMapping("pass")
    public ResponseEntity<Map> messagePass(@RequestBody String[] id){
        try {
            Map<String, String> message = this.messagePassAndRejectService.messagePass(id);
            if (ObjectUtil.isNotEmpty(message)) {
                return ResponseEntity.ok(message);
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("通过操作失败");
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


    /**
     * 消息拒绝
     * @param id
     * @return
     */
    @PostMapping("reject")
    public ResponseEntity<Map> messageReject(@RequestBody String[] id){
        try {
            Map<String, String> message = this.messagePassAndRejectService.messageReject(id);
            if (ObjectUtil.isNotEmpty(message)) {
                return ResponseEntity.ok(message);
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("消息拒绝操作失败");
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
